package com.example.dao.impl;

import com.example.Pojo.HairMaster;
import com.example.Pojo.Member;
import com.example.Pojo.User;
import com.example.dao.UserDao;

import java.util.List;

public class UserDaoImpl extends BaseDao implements UserDao {

    @Override
    public User queryUser(String username) {
        String sql ="select * from admin where username=?";
        return queryForOne(User.class,sql,username);
    }

    @Override
    public User queryUserAndPassword(String username, String password) {
        return null;
    }

    @Override
    public int saveUser(User user) {
        String sql = "insert into admin values(?,?,?,?,?)";
        return update(sql,user.getId(),user.getUsername(),user.getTellphone(),user.getPassword(),user.getRegisttime());
    }

    @Override
    public List<Member> showAllUser() {
        String sql = "select * from member";
        return queryForList(Member.class,sql);
    }

    @Override
    public int updateTimes(Member member,String type,int times,String time) {
        String sql = "update member set "+type+"=? ,latest_operating_time=? where tellphone="+member.getTellphone();
        return update(sql,times,time);
    }

    @Override
    public Member getMember(String tellphone) {
        String sql = "select * from member where tellphone=?";
        return queryForOne(Member.class,sql,tellphone);
    }

    @Override
    public int deleteUser(String tellphone) {
        String sql = "delete from member where tellphone=?";
        return update(sql,tellphone);
    }

    @Override
    public int insertMeb(Member member) {
        String sql = "insert into member values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        return update(sql,member.getUsername(),member.getSex(),member.getTellphone(),
                member.getRegisttime(),member.getType(),member.getConsume(),member.getHaircut(),
                member.getPerm(),member.getWash_protect(),member.getHairroot(),member.getColour(),
                member.getWash(),member.getBlack(),member.getInvest(),member.getRemarks(),member.getLatest_operating_time()
        );
    }

    @Override
    public int updateCard(String invest, String tellphone) {
        String sql = "update member set invest=? where tellphone=?";
        return update(sql,invest,tellphone);
    }

    @Override
    public int updateMember(Member member) {
        String sql = "update member set haircut=?,perm=?,wash_protect=?,hairroot=?,colour=?,wash=?,black=? where tellphone=?";
        return update(sql,member.getHaircut(),member.getPerm(),member.getWash_protect(),
                          member.getHairroot(),member.getColour(),member.getWash(),
                          member.getBlack(),member.getTellphone());
    }

    @Override
    public int updateCost(String tellphone, String consume,String invset) {
        String sql = "update member set invest=?,consume=? where tellphone=?";
        return update(sql,invset,consume,tellphone);
    }

    @Override
    public int updatePwd(String telphone, String password) {
        String sql = "update admin set password=? where tellphone=?";
        return update(sql,password,telphone);
    }

    @Override
    public int insertOperation(Member m,String op,String time) {
        String sql = "insert into operation values(?,?,?,?,?,?,?,?)";
        return update(sql,m.getId(),m.getUsername(),m.getSex(),m.getTellphone(),m.getType(),op,m.getRegisttime(),time);
    }

    @Override
    public List<HairMaster> findAllMaster() {
        String sql = "select * from hairmaster";
        return queryForList(HairMaster.class,sql);
    }

}
